home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / nwtp06 / tstsema2.pas < prev    next >
Pascal/Delphi Source File  |  1996-07-10  |  2KB  |  87 lines

  1. {$X+,B-,V-}
  2. Program tstsema2;
  3.  
  4. { Example for the nwSema unit / NwTP 0.6 API. (c) 1993,1995, R.Spronk }
  5.  
  6. uses nwMisc,nwConn,nwSema;
  7.  
  8.  
  9. Var ConnNbr:Byte;
  10.     seqNbr:Word;
  11.     NbrOfSema:Byte;
  12.     SemaInfo:TconnSema;
  13.  
  14.     SemValue:Integer;
  15.     info:TsemaInfoList;
  16.  
  17.     t:byte;
  18.     s:string;
  19.  
  20.     handle4,handle5,
  21.     handle6,handle7:LongInt;
  22.     openCount:word;
  23. begin
  24.  
  25. connNbr:=2;seqNbr:=0;
  26.  
  27. OpenSemapHore('SEMA4',4,handle4,openCount);
  28. OpenSemaphore('SEMAPHORE5',5,handle5,OpenCount);
  29. OpenSemapHore('SEM6',6,handle6,OpenCount);
  30. OpenSemapHore('SEMAP7',7,handle7,OpenCount);
  31.  
  32. writeln('Semaphores have been opened..');
  33. writeln;
  34. writeln('<RETURN> to continue..');
  35. readln(s);
  36.  
  37. GetConnectionNumber(connNbr); { my connection number }
  38.  
  39. seqNbr:=1;
  40. REPEAT
  41. IF NOT GetConnectionsSemaphores(ConnNbr,seqNbr,NbrOfSema,SemaInfo)
  42.  then begin
  43.       writeln('GetConnectionsSemaphores returned error #', nwSema.result);
  44.       seqNbr:=0;
  45.       end
  46.  else begin
  47.       writeln;
  48.       writeln('NbrOfSema Left to Scan: ',NbrOfSema);
  49.       writeln('Next seq Nbr          : ',seqNbr);
  50.  
  51.       with SemaInfo
  52.        do begin
  53.           writeln('Sema Name:',Name);
  54.           writeln('Opencount:',OpenCount);
  55.           writeln('Value    :',Value);
  56.           writeln('TaskNbr  :',taskNbr);
  57.           end;
  58.       end;
  59.  
  60. UNTIL seqNbr=0;
  61.  
  62.  
  63. seqNbr:=1;
  64. REPEAT
  65. IF GetSemaphoreInformation('SEMA4',seqNbr,
  66.                            OpenCount,SemValue,NbrOfSema,info)
  67.  then begin
  68.       writeln;
  69.       writeln('Test of GetSemaphoreInformation...');
  70.       writeln('Connections using semaphore:',Opencount);
  71.       writeln('Semaphore value:',semvalue);
  72.  
  73.       If NbrOfSema>100
  74.        then NbrOfSema:=100;
  75.       for t:=1 to NbrOfSema
  76.        do writeln('Record #:',t,' Connection: ',info[t].ConnNbr,' Task: ',info[t].taskNbr);
  77.       end
  78.  else writeln('GetSemaphoreInformation returned error #', nwSema.result);
  79. UNTIL seqNbr=0;
  80.  
  81. CloseSemaphore(handle4);
  82. CloseSemaphore(handle5);
  83. CloseSemaPhore(handle6);
  84. CloseSemaphore(handle7);
  85. end.
  86.  
  87.